package com.wicket.okrframework.web.contorller;

import com.github.pagehelper.Page;
import com.wicket.okrframework.biz.service.PositionService;
import com.wicket.okrframework.biz.service.dto.req.*;
import com.wicket.okrframework.biz.service.dto.res.*;
import com.wicket.okrframework.common.ro.OkrResult;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：
 * @date ：
 *
 *
 * @version 1.0
 */
@RestController
@RequestMapping("/base/position/")
public class PositionController {

    @Autowired
    PositionService positionService;

    /**
   * D1-3查询职务详情
   */
    @PostMapping("queryPositionDetail")
    public OkrResult<QueryPositionDetailRespDto> queryPositionDetail(@RequestBody @Validated QueryPositionDetailReqDto reqDTO){
    return OkrResult.success(positionService.queryPositionDetail(reqDTO));
    }

    /**
   * D1-3查询职务列表（边界）
   */
    @PostMapping("queryPositionListBorder")
    public OkrResult<QueryPositionListBorderRespDto> queryPositionListBorder(@RequestBody @Validated QueryPositionListBorderReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryPositionListBorderRespDto retData = positionService.queryPositionListBorder(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-3查询职务名称详情
   */
    @PostMapping("queryPositionTitleDetail")
    public OkrResult<QueryPositionTitleDetailRespDto> queryPositionTitleDetail(@RequestBody @Validated QueryPositionTitleDetailReqDto reqDTO){
    return OkrResult.success(positionService.queryPositionTitleDetail(reqDTO));
    }

    /**
   * D1-3修改职务名称
   */
    @PostMapping("updatePositionTitle")
    public OkrResult<UpdatePositionTitleRespDto> updatePositionTitle(@RequestBody @Validated UpdatePositionTitleReqDto reqDTO){
    return OkrResult.success(positionService.updatePositionTitle(reqDTO));
    }

    /**
   * D1-3新增职务名称
   */
    @PostMapping("addPositionTitle")
    public OkrResult<AddPositionTitleRespDto> addPositionTitle(@RequestBody @Validated AddPositionTitleReqDto reqDTO){
    return OkrResult.success(positionService.addPositionTitle(reqDTO));
    }

    /**
   * D1-3查询职务名称列表
   */
    @PostMapping("queryPositionTitleList")
    public OkrResult<QueryPositionTitleListRespDto> queryPositionTitleList(@RequestBody @Validated QueryPositionTitleListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryPositionTitleListRespDto retData = positionService.queryPositionTitleList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-3查询编制去重职务列表（边界）
   */
    @PostMapping("queryNoRepPositionList")
    public OkrResult<QueryNoRepPositionListRespDto> queryNoRepPositionList(@RequestBody @Validated QueryNoRepPositionListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryNoRepPositionListRespDto retData = positionService.queryNoRepPositionList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-3查询职务列表
   */
    @PostMapping("queryPositionList")
    public OkrResult<QueryPositionListRespDto> queryPositionList(@RequestBody @Validated QueryPositionListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryPositionListRespDto retData = positionService.queryPositionList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-3查询编制下职务列表
   */
    @PostMapping("queryStaffingPositionList")
    public OkrResult<QueryStaffingPositionListRespDto> queryStaffingPositionList(@RequestBody @Validated QueryStaffingPositionListReqDto reqDTO){
    Page<?> page = CommonFunctionHelper.startPage(reqDTO.getPageNum(),reqDTO.getPageSize());

        QueryStaffingPositionListRespDto retData = positionService.queryStaffingPositionList(reqDTO);

        retData.setPageNum(page.getPageNum());
        retData.setPageSize(page.getPageSize());
        retData.setTotalNum(page.getTotal());
        return OkrResult.success(retData);
    
    }

    /**
   * D1-3存档职务
   */
    @PostMapping("archivePosition")
    public OkrResult<ArchivePositionRespDto> archivePosition(@RequestBody @Validated ArchivePositionReqDto reqDTO){
    return OkrResult.success(positionService.archivePosition(reqDTO));
    }

    /**
   * D1-3-修改职务
   */
    @PostMapping("updatePosition")
    public OkrResult<UpdatePositionRespDto> updatePosition(@RequestBody @Validated UpdatePositionReqDto reqDTO){
    return OkrResult.success(positionService.updatePosition(reqDTO));
    }

    /**
   * D1-3-新增职务
   */
    @PostMapping("addPosition")
    public OkrResult<AddPositionRespDto> addPosition(@RequestBody @Validated AddPositionReqDto reqDTO){
    return OkrResult.success(positionService.addPosition(reqDTO));
    }
/**
   * D1-3查询职务详情(边界)
   */
    @PostMapping("queryPositionDetailBorder")
    public OkrResult<QueryPositionDetailBorderRespDto> queryPositionDetailBorder(@RequestBody @Validated QueryPositionDetailBorderReqDto reqDTO){
    return OkrResult.success(positionService.queryPositionDetailBorder(reqDTO));
    }
}
